package com.farben.web.controller.aging;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.farben.common.annotation.Log;
import com.farben.common.core.controller.BaseController;
import com.farben.common.core.domain.AjaxResult;
import com.farben.common.enums.BusinessType;
import com.farben.system.domain.AgingDesignConfigInfo;
import com.farben.system.service.IAgingDesignConfigInfoService;
import com.farben.common.utils.poi.ExcelUtil;
import com.farben.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;

/**
 * 适老化Controller
 *
 * @author farben
 * @date 2023-05-16
 */
@Api("适老化配置信息")
@RestController
@RequestMapping("/system/aging_design/configInfo")
public class AgingDesignConfigInfoController extends BaseController {
    @Autowired
    private IAgingDesignConfigInfoService agingDesignConfigInfoService;

    /**
     * 查询适老化配置信息列表
     */
    @ApiOperation("查询适老化配置信息列表")
    @PreAuthorize("@ss.hasPermi('system:configInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgingDesignConfigInfo agingDesignConfigInfo) {
        startPage();
        List<AgingDesignConfigInfo> list = agingDesignConfigInfoService.selectAgingDesignConfigInfoList(agingDesignConfigInfo);
        return getDataTable(list);
    }

    /**
     * 导出适老化配置信息列表
     */
    @ApiOperation("导出适老化配置信息列表")
    @ApiImplicitParam(name = "AgingDesignConfigInfo", value = "应用信息", dataType = "AgingDesignConfigInfo")
    @PreAuthorize("@ss.hasPermi('system:configInfo:export')")
    @Log(title = "适老化", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AgingDesignConfigInfo agingDesignConfigInfo) {
        List<AgingDesignConfigInfo> list = agingDesignConfigInfoService.selectAgingDesignConfigInfoList(agingDesignConfigInfo);
        ExcelUtil<AgingDesignConfigInfo> util = new ExcelUtil<AgingDesignConfigInfo>(AgingDesignConfigInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取适老化配置信息详细信息
     */
    @ApiOperation("获取适老化配置信息详细信息")
    @ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('system:configInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(agingDesignConfigInfoService.selectAgingDesignConfigInfoById(id));
    }

    /**
     * 新增适老化配置信息
     */
    @ApiOperation("新增适老化配置信息")
    @ApiImplicitParam(name = "AgingDesignConfigInfo", value = "应用信息", dataType = "AgingDesignConfigInfo")
    @PreAuthorize("@ss.hasPermi('system:configInfo:add')")
    @Log(title = "适老化", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgingDesignConfigInfo agingDesignConfigInfo) {
        return toAjax(agingDesignConfigInfoService.insertAgingDesignConfigInfo(agingDesignConfigInfo));
    }

    /**
     * 更新适老化配置信息
     */
    @ApiOperation("更新后管应用信息")
    @ApiImplicitParam(name = "AgingDesignConfigInfo", value = "应用信息", dataType = "AgingDesignConfigInfo")
    @PreAuthorize("@ss.hasPermi('system:configInfo:edit')")
    @Log(title = "适老化", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgingDesignConfigInfo agingDesignConfigInfo) {
        return toAjax(agingDesignConfigInfoService.updateAgingDesignConfigInfo(agingDesignConfigInfo));
    }

    /**
     * 删除适老化配置信息
     */
    @ApiOperation("删除适老化配置信息")
    @ApiImplicitParam(name = "ids", value = "主键Ids", required = true, dataType = "long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('system:configInfo:remove')")
    @Log(title = "适老化", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(agingDesignConfigInfoService.deleteAgingDesignConfigInfoByIds(ids));
    }

    /**
     * 发布适老化配置信息
     */
    @ApiOperation("发布适老化配置信息")
    @ApiImplicitParam(name = "AgingDesignConfigInfo", value = "应用信息", dataType = "AgingDesignConfigInfo")
    @PreAuthorize("@ss.hasPermi('system:configInfo:release')")
    @Log(title = "适老化", businessType = BusinessType.OTHER)
    @PutMapping("/release")
    public AjaxResult release(@RequestBody AgingDesignConfigInfo agingDesignConfigInfo) {
        agingDesignConfigInfo.setConfirm("1");
        return toAjax(agingDesignConfigInfoService.releaseAgingDesignConfigInfo(agingDesignConfigInfo));
    }

    /**
     * 保存适老化配置信息
     */
    @ApiOperation("保存适老化配置信息")
    @ApiImplicitParam(name = "AgingDesignConfigInfo", value = "应用信息", dataType = "AgingDesignConfigInfo")
    @PreAuthorize("@ss.hasPermi('system:configInfo:setPageConfig')")
    @Log(title = "适老化", businessType = BusinessType.OTHER)
    @PutMapping("/setPageConfig")
    public AjaxResult setPageConfig(@RequestBody AgingDesignConfigInfo agingDesignConfigInfo) {
        agingDesignConfigInfo.setConfirm("0");
        boolean isSuccess = agingDesignConfigInfoService.setPageConfig(agingDesignConfigInfo);
        return isSuccess ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 保存适老化配置信息
     */
    @ApiOperation("查询页面适老化配置信息")
    @ApiImplicitParam(name = "AgingDesignConfigInfo", value = "应用信息", dataType = "AgingDesignConfigInfo")
    @PreAuthorize("@ss.hasPermi('system:configInfo:getPageConfig')")
    @PutMapping("/getPageConfig")
    public AjaxResult getPageConfig(HttpServletRequest request, @RequestBody AgingDesignConfigInfo agingDesignConfigInfo) {
        AgingDesignConfigInfo result =  agingDesignConfigInfoService.queryAppPageInfo(agingDesignConfigInfo);
        return AjaxResult.success(result);
    }

    @PostMapping("/getPageConfigNoAuth")
    public AjaxResult getPageConfigNoAuth(HttpServletRequest request, @RequestBody AgingDesignConfigInfo agingDesignConfigInfo) {
        AgingDesignConfigInfo result =  agingDesignConfigInfoService.queryAppPageInfo(agingDesignConfigInfo);
        return AjaxResult.success(result);
    }
}
